home *** CD-ROM | disk | FTP | other *** search
- {$APPTYPE CONSOLE}
-
- program hpj2inc;
-
- uses
- Classes,
- SysUtils,
- IniFiles;
-
- procedure Convert(fNameHPJ, fNameINC: string);
- var
- fINC: text;
- keys: TStringList;
- i: integer;
-
- function Cleanup(s: string): string;
- var
- i: integer;
- begin
- for i := Length(s) downto 1 do
- if not (s[i] in ['A'..'Z','a'..'z','0'..'9','_']) then Delete(s,i,1);
- Result := '_'+s;
- end; { Cleanup }
-
- function Replace(s: string): string;
- var
- p: integer;
- begin
- p := Pos(';',s);
- if p > 0 then begin
- Delete(s,p,1);
- Insert('//',s,p);
- end;
- Result := s;
- end; { Replace }
-
- function Fixup(s: string): string;
- var
- p: integer;
- begin
- p := Pos('//',s);
- if p < 40 then Insert(Copy(' ',1,40-p),s,p);
- p := Pos('//',s);
- Insert(';',s,p);
- Result := s;
- end; { Fixup }
-
- begin
- with TIniFile.Create(fNameHPJ) do begin
- try
- keys := TStringList.Create;
- try
- ReadSection('MAP',keys);
- Assign(fINC,fNameINC);
- Rewrite(fINC);
- if keys.Count > 0 then begin
- Writeln(fINC,'const');
- for i := 0 to keys.Count-1 do
- Writeln(fINC,' ',Fixup(Cleanup(keys[i])+'='+Replace(ReadString('MAP',keys[i],''))));
- end;
- Close(fINC);
- finally keys.Free; end;
- finally Free; end;
- end;
- end; { Convert }
-
- begin
- if ParamCount <> 2 then Writeln('Usage: hpj2inc source.hpj dest.inc')
- else Convert(ParamStr(1),ParamStr(2));
- end.
-